<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>

    const timeout = ms => new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve();
        }, ms);
    });

    const ajax1 = () => timeout(2000).then(() => {
        console.log('1');
        return 1;
    });

    const ajax2 = () => timeout(1000).then(() => {
        console.log('2');
        return 2;
    });

    const ajax3 = () => timeout(2000).then(() => {
        console.log('3');
        return 3;
    });

    const mergePromise = ajaxArray => {
        // 在这里实现你的代码
        var data = [];
        var sequence = Promise.resolve();
        console.log(ajaxArray)
        ajaxArray.forEach(function(item) {
            sequence = sequence.then(item).then(function(res) {
                data.push(res);
                return data;
            });
        })
        return sequence;
    }

    mergePromise([ajax1, ajax2, ajax3]).then(data => {

        console.log('done');
        console.log(data); // data 为 [1, 2, 3]
    });

</script>
</body>
</html>